#define F_CPU 8000000L
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

#define BAUD 38400
#include <util/setbaud.h>

void uart_init(void)
{
    UBRRH = UBRRH_VALUE;
    UBRRL = UBRRL_VALUE;
    #if USE_2X
    UCSRA |= (1 << U2X);
    #else
    UCSRA &= ~(1 << U2X);
    #endif
    UCSRB |= 0x18;
}

int uart_send_byte(char c)
{
    loop_until_bit_is_set(UCSRA, UDRE);
    UDR = c;

    return 0;
}

int main (void)
{
    PORTB = 0x00;
    DDRB = 0xFF;

    uart_init();

    int x = 65;

    while(1)
    {
        uart_send_byte(x);
        _delay_ms(200);

        PORTB ^= 0x0F;

        _delay_ms(200);
        
        PORTB ^= 0x0F;

        x++;
        if(x>122)
            x = 65;
    }
}
